import api from '../../api/api'
import * as types from '../mutation-types'

// initial state
const state = {
  hotSpotList: [],

}

  /**
   * 这里的getter永远都会将state传入。
   * getters
   */
const getters = {
    hotSpotList: state => state.hotSpotList,
}

/**
 * actions
 * 这个包含的是 commit 和 state 或者只包含commit
 * @type {{getHotSpotList: (({ commit, state }:{commit: *, state: *}))}}
 */
const actions = {
  getHotSpotList ({ commit, state }) {
          api.getHotSpot((list)=>{
              commit(types.GET_HOT_SPOT_LIST,{list})
          })
  }
}


/**
 * 多个mutation可以接收同一个action
 * mutations
 * 执行语句
 * @type {{}}
 * 特别注意参数 {}
 */
const mutations = {
  [types.GET_HOT_SPOT_LIST](state,{list}){
    state.hotSpotList = list;
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
